<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
	
	protected $user;
	
	function __construct(){
		parent::__construct();
		header("Content-type:text/html; charset='utf-8");
	}
	
	function index(){
		$this->redirect("Home/Index/toStart");
	}
	function toStart(){
		if(getUser("userid") == NULL)
			$this->initUser();
		//菜单url加载
		$menuUrl	= M("menuurl")->select();
		$myMenu	= array();
		foreach($menuUrl as $url){
			if(doAuth(getUser("userid"),$url['url']) == 10){
				$url['childurl']	= C("CHILD_URL.".$url['url']);
				array_push($myMenu, $url);
			}
		}
		
		session("bw_MyMenu", $myMenu);
		//$this->assign("myMenu", $myMenu);
		$this->display("index");
		//$this->display("index");
		//$this->redirect("/Home/Bug/getBugList");
	}
	
	function initUser(){
		if(cookie("bw_username") != NULL && cookie("bw_password") != NULL){
			$userData	= array('username'=>cookie('bw_username'), 'password'=>cookie('bw_password'));
			$status = D('users')->toLogin($userData,1);
			if($status != 10){
				$this->redirect('/Home/User/toLogin');
			}
		}else{
			$this->redirect('/Home/User/toLogin');
		}
	}
	
	function upLoadFile(){
		if (!empty($_FILES)) {
            //图片上传设置
            $config = array(
                'rootPath'	 =>    'Public/Image/Bug/',  
                'exts'       =>    array('jpg', 'gif', 'png', 'jpeg'),  
                'autoSub'    =>    false,   
            );
            $upload = new \Think\Upload($config);// 实例化上传类
            $images = $upload->upload($_FILES);
          
            if($images){
                $info=$images['Filedata']['savename'];
                echo $info;
            }
            else{
                $this->error($upload->getError());
            }
        }
	}
}